//由先序，中序遍历序列构造二叉树
public class TreeByPreIn {
}
class TreeByPreInSolution {
    public TreeNode buildTree(int[] preorder, int[] inorder) {
        return process(inorder,0,inorder.length-1,preorder,0,preorder.length-1);
    }
    TreeNode process(int[] inorder,int il,int ir,int[] preorder,int pl,int pr){
        if(pl>pr)return null;
        TreeNode root = new TreeNode(preorder[pl]);
        int index = il;
        while(inorder[index]!=preorder[pl]&&index<=ir)index++;
        int left = index-il;
        root.left = process(inorder,il,index-1,preorder,pl+1,pl+left);
        root.right = process(inorder,index+1,ir,preorder,pl+left+1,pr);
        return root;
    }
}